﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AP.Framework.Infrastructure.Entities;
using AP.Framework.Infrastructure.Repositories.IRepositories;
using AP.Framework.Utilities.MvcPager;
namespace ApCMS.Areas.Admin.Controllers
{
    public class JobCategoryController : Controller
    {
        IJobCategory _jobCategory;
        public JobCategoryController(IJobCategory jobCategory)
        {
            _jobCategory = jobCategory;
        }
        public ActionResult Index(int? page)
        {
            var jobCategorylList = _jobCategory.GetAll();
            return View(jobCategorylList.AsQueryable().ToPagedList(page ?? 1, 10));
        }
        public ActionResult Add()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Add(cms_JobCategory model)
        {
            if (ModelState.IsValid)
            {
                model.CreateBy = "Admin";
                model.CreateTime = DateTime.Now.Date;
                _jobCategory.Add(model);
            }
            return RedirectToAction("Index");
        }
        public ActionResult Edit(int jobCategoryId)
        {
            cms_JobCategory param = _jobCategory.FindById(jobCategoryId);
            return View(param);
        }
        [HttpPost]
        public ActionResult Edit(cms_JobCategory model)
        {
            if (ModelState.IsValid)
            {
                model.ModifyBy = "Admin";
                model.ModifyTime = DateTime.Now.Date;
                _jobCategory.Modify(model);
            }
            return RedirectToAction("Index");
        }

        public ActionResult Delete(int jobCategoryId)
        {
            cms_JobCategory model = _jobCategory.FindById(jobCategoryId);
            _jobCategory.Remove(model);
            return RedirectToAction("Index");
        }

    }
}
